﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Entity;
using Runda.CMS.Bll;

namespace Runda.CMS.Portal.SyncManage
{
    public partial class InstrumentList : BasePage
    {
        public Guid CategoryID
        {
            get
            {
                if (hiddenCategoryID.Value == string.Empty) return Guid.Empty;
                else return new Guid(hiddenCategoryID.Value);
            }
            set
            {
                hiddenCategoryID.Value = value.ToString();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                BindInstrumentList(1);
            }
        }

        private void BindInstrumentList(int pageindex)
        {
            if (Request.QueryString["categoryGUID"] != null && Request.QueryString["categoryGUID"].ToString() != "")
            {
                hiddenCategoryID.Value = Request.QueryString["categoryGUID"];
                List<SqlDbParameter> parms = new List<SqlDbParameter>();
                SqlDbParameter parm = new SqlDbParameter();
                parm.ColumnName = "categoryGUID";
                parm.ColumnType = System.Data.DbType.String;
                parm.ParameterName = "@categoryGUID";
                parm.ParameterValue = Request.QueryString["categoryGUID"].ToString();
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
                parms.Add(parm);

                int RecordCount = 0;
                List<CtrtInstrumentEntity> list = new CtrtInstrumentBll().GetAll<CtrtInstrumentEntity>(parms, "CreatedOn desc", AspNetPager1.PageSize, pageindex, out RecordCount);

                RepeaterInstruments.DataSource = list;
                RepeaterInstruments.DataBind();
                AspNetPager1.RecordCount = RecordCount;
            }
            if (Request.QueryString["InstrumentGUID"] != null && Request.QueryString["InstrumentGUID"].ToString() != "")
            {
                List<SqlDbParameter> parms = new List<SqlDbParameter>();
                SqlDbParameter parm = new SqlDbParameter();
                parm.ColumnName = "instrumentGUID";
                parm.ColumnType = System.Data.DbType.String;
                parm.ParameterName = "@instrumentGUID";
                parm.ParameterValue = Request.QueryString["InstrumentGUID"].ToString();
                parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
                parms.Add(parm);

                List<CtrtInstrumentEntity> list = new CtrtInstrumentBll().GetAll<CtrtInstrumentEntity>(parms);
                RepeaterInstruments.DataSource = list;
                RepeaterInstruments.DataBind();
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindInstrumentList(AspNetPager1.CurrentPageIndex);
        } 
    }
}
